"use strict";

const Controller = require("egg").Controller;

class LoginController extends Controller {
  async index() {
    this.ctx.body = "hello";
  }

  // post请求 用户注册
  async register() {
    try {
      let res = await this.ctx.service.userLogin.userRegister();
      if (res) {
        this.ctx.body = {
          code: 200,
          data: res
        };
      }
    } catch (e) {
      this.ctx.body = {
        code: 400,
        data: {
          msg: "错误"
        }
      };
    }
  }

  async userUpdate() {
    try {
      let res = await this.ctx.service.userLogin.update();
      if (res) {
        this.ctx.body = {
          code: 200,
          data: res
        };
      }
    } catch (e) {
      this.ctx.body = {
        code: 400,
        data: {
          msg: "错误"
        }
      };
    }
  }

  //用户登录
  async signIn() {
    console.log(await this.ctx.service.userLogin.userSignIn());
    try {
      let res = await this.ctx.service.userLogin.userSignIn();
      if (res) {
        this.ctx.body = {
          code: 200,
          data: res
        };
      }
    } catch (e) {
      this.ctx.body = {
        code: 400,
        data: {
          msg: "错误"
        }
      };
    }
  }
}

module.exports = LoginController;
